﻿using System.Collections.Generic;
using System.Threading.Tasks;

namespace SqlSugarCore.Dal.BaseRealize
{
    /// <summary>
    /// 基本更新相关
    /// </summary>
    /// <typeparam name="T"></typeparam>
    public partial class BaseDal<T> where T : class, new()
    {
        /// <summary>
        /// 更新数据
        /// </summary>
        /// <param name="entity"></param>
        /// <returns>返回受影响的行数</returns>
        public int Update(T entity)
        {
            var updateNum = this._sqlSugarClient.Updateable<T>(entity).ExecuteCommand();
            return updateNum;
        }

        /// <summary>
        /// 更新数据 (异步)
        /// </summary>
        /// <param name="entity"></param>
        /// <returns>返回受影响的行数</returns>
        public async Task<int> UpdateAsync(T entity)
        {
            var updateNum = await this._sqlSugarClient.Updateable<T>(entity).ExecuteCommandAsync();
            return updateNum;
        }

        /// <summary>
        /// 批量更新数据
        /// </summary>
        /// <param name="entities"></param>
        /// <returns>返回受影响的行数</returns>
        public int Update(List<T> entities)
        {
            var updateNum = this._sqlSugarClient.Updateable<T>(entities).ExecuteCommand();
            return updateNum;
        }

        /// <summary>
        /// 批量更新数据(异步)
        /// </summary>
        /// <param name="entities"></param>
        /// <returns>返回受影响的行数</returns>
        public async Task<int> UpdateAsync(List<T> entities)
        {
            var updateNum = await this._sqlSugarClient.Updateable<T>(entities).ExecuteCommandAsync();
            return updateNum;
        }

    }
}